// script.js
const photos = [
    '1.jpg',
    '2.jpg',
    '3.jpg',
    '4.jpg',
    '5.jpg',
    '6.jpg',
];

const photoContainer = document.getElementById('photo-container');
let currentIndex = 0;

// 动态生成所有图片元素
photos.forEach((photo, index) => {
    const imgElement = document.createElement('img');
    imgElement.src = photo;
    imgElement.alt = `女朋友照片 ${index + 1}`;
    imgElement.classList.add(index === 0 ? 'active' : ''); // 默认第一张为激活状态
    photoContainer.appendChild(imgElement);
});

// 切换图片函数
function updatePhoto(newIndex) {
    const images = document.querySelectorAll('#photo-container img');
    images[currentIndex].classList.remove('active'); // 隐藏当前图片
    currentIndex = (newIndex + photos.length) % photos.length; // 确保索引循环
    images[currentIndex].classList.add('active'); // 显示新图片
}

// 按钮事件监听
document.getElementById('next').addEventListener('click', () => {
    updatePhoto(currentIndex + 1); // 下一张
});

document.getElementById('prev').addEventListener('click', () => {
    updatePhoto(currentIndex - 1); // 上一张
});
